package org.wll.controller;

import org.wll.entity.Employee;
import org.wll.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("emp")
public class EmployeeController {

    @Autowired
    EmployeeService empService;

    @GetMapping("/{eid}")
    //根据id查找emp信息
    public Employee findEmpById(@PathVariable("eid") Integer eid) {
        Employee emp = empService.findEmpById(eid);
        return emp;
    }

    //查看所有员工信息
    @GetMapping("/all")
    public List<Employee> findAllEmps() {
        return empService.findAllEmps();
    }

    //添加员工信息
    @PostMapping("/add")
    public Employee addEmp(Employee emp) {
        Employee emp1 = empService.addEmp(emp);
        return emp1;
    }


    //修改员工信息
    @PutMapping("/update")
    public Employee updeEmp(Employee emp) {
        Employee emp1 = empService.updeEmp(emp);
        return emp1;
    }

    //根据id删除员工信息
    @DeleteMapping("/delete/{eid}")
    public void deleteEmpById(@PathVariable("eid") Integer eid) {
        empService.deleteEmpById(eid);
    }


}
